// =================================================================
// File: Block.cpp
// Desc: Implementation of functions for Block class
// =================================================================

// =================================================================
// INCLUDES
// =================================================================

#include <iostream>
#include <cstring>
#include "Block.h"

using namespace std;

// =================================================================
// FUNCTIONS
// =================================================================

// =================================================================
// Name: Block::Block
// Desc: Initializes a Block with given data array
// Args: char* bytes - Array of size BLOCK_SIZE containing data
// =================================================================
Block::Block(char *bytes)
{
  SetBytes(bytes);
}

// =================================================================
// Name: Block::~Block
// Desc: Destructor for Block
// =================================================================
Block::~Block()
{
}

// =================================================================
// Name: Block::SetBytes
// Desc: Sets the data in a Block to the data in a given array
// Args: char* bytes - Array of size BLOCK_SIZE containing data
// =================================================================
void Block::SetBytes(char *bytes)
{
    for (int i = 0; i < BLOCK_SIZE; i++) {
        SetByte(bytes[i], i);
    }
}

// =================================================================
// Name: Block::SetByte
// Desc: Sets a single value of bytes array at given index
// Args: char byte - data to set
//       int index - location in array to set data
// =================================================================
void Block::SetByte(char byte,int index){
  if (index >= 0 && index < BLOCK_SIZE)
    bytes[index] = byte;
  else
    cout << "Attempting to SetByte outside of array range with value " << index << endl;
}

// =================================================================
// Name: Block::GetByte
// Desc: Returns the value in data array at specified index
// Args: int index - location in array to return data from
// Rets: single char containing data specified
// =================================================================
char Block::GetByte(int index)
{
  return bytes[index];
}

// =================================================================
// Name: Block::GetBytes
// Desc: Returns the whole data array
// Rets: array of size BLOCK_SIZE containing all data in block
// =================================================================
char *Block::GetBytes()
{
  return bytes;
}
